package com.innjia.shiro.utils;

import com.innjia.base.common.Constant;
import com.innjia.base.enums.UserSysRoleEnum;
import com.innjia.sys.entity.UserEntity;
import org.apache.shiro.authc.UsernamePasswordToken;

import java.util.UUID;

/**
 * <br>
 * 2017-11-15
 *
 * @author zhouxianglh@gmail.com
 */
public class LoginToken extends UsernamePasswordToken {
    /**
     * 默认密码,给非用户名,密码登录验证使用
     */
    private static final String DEFAULT_PASSWORD = Constant.DEF_PASSWORD;

    /**
     * 默认用户名,给非用户名,密码登录验证使用
     */
    private static final String DEFAULT_USER = Constant.SUPERR_USER;

    private String mobile;

    private String code;

    private UserSysRoleEnum userRole;

    private String token;

    private String uid;

    private String loginSrc;

    private UserEntity userEntity;

    public LoginToken(String username, String password, boolean rememberMe, String host, String mobile, String code, UserSysRoleEnum userRole, String token, String uid, String loginSrc) {
        super(username, password, rememberMe, host);
        this.mobile = mobile;
        this.code = code;
        this.userRole = userRole;
        this.token = token;
        this.uid = uid;
        this.loginSrc = loginSrc;
    }

    public static LoginToken buildAdmin(String username, String password, boolean rememberMe, String host) {
        return new LoginToken(username, password, rememberMe, host, null, null, UserSysRoleEnum.ADMIN, null, null, null);
    }

    public static LoginToken buildApp(String host, String mobile, String code, UserSysRoleEnum userRole, String uid, String loginSrc) {
        String token = UUID.randomUUID().toString();
        return new LoginToken(DEFAULT_USER, DEFAULT_PASSWORD, false, host, mobile, code, userRole, token, uid, loginSrc);
    }

    public static LoginToken buildToken(String host, String token, UserSysRoleEnum userRole) {
        return new LoginToken(DEFAULT_USER, DEFAULT_PASSWORD, false, host, null, null, userRole, token, null, null);
    }

    public UserEntity getUserEntity() {
        return userEntity;
    }

    public void setUserEntity(UserEntity userEntity) {
        this.userEntity = userEntity;
    }

    public String getLoginSrc() {
        return loginSrc;
    }

    public void setLoginSrc(String loginSrc) {
        this.loginSrc = loginSrc;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public UserSysRoleEnum getUserRole() {
        return userRole;
    }

    public void setUserRole(UserSysRoleEnum userRole) {
        this.userRole = userRole;
    }
}
